<!DOCTYPE html>
<html lang="en">
  <head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta content="" name="keywords">

  <title> 杂技浅尝 - </title>
  <meta name="description" content="" />
  <meta property="og:title" content="杂技浅尝" />
  <meta name="twitter:title" content="杂技浅尝" />
  <meta name="author" content="{Description { .Site.Author.name }}"/>
  <meta name="twitter:card" content="summary" />
  <meta property="og:url" content="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/" />
  <meta property="og:type" content="website" />
  <meta property="og:site_name" content="听风的小站" />

  <meta name="generator" content="Hugo 0.67.0" />
  <link rel="canonical" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/" />
  <link rel="alternate" href="https://systemime.github.io/index.xml" type="application/rss+xml" title="听风的小站">
  <script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/jquery-1.12.4.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  
  
  <link rel="stylesheet" href="https://systemime.github.io/css/main.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/my.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/pace.css" />
  <link rel="stylesheet" href="https://cdn.plyr.io/3.4.7/plyr.css">
  <link rel="stylesheet" href="https://systemime.github.io/css/lightgallery.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/baguetteBox.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/search.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/reward.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/share.min.css" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" />
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" />
  <link rel="stylesheet" href="https://systemime.github.io/css/pygment_highlights.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/highlight.min.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/toc.css" />
  <link rel="stylesheet" href="https://systemime.github.io/css/lightbox.css" />
  <link rel="stylesheet" href="https://systemime.github.io/live2d/css/live2d.css" />
  
  <link href="https://systemime.github.io/css/video-js.css" rel="stylesheet">


<meta name="baidu-site-verification" content="g8IYR9SNLF" />
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cffe439e37449bb1c07ab26ab56484bb";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

<link rel="stylesheet" href="https://systemime.github.io/css/prism.css" />









<script src="https://systemime.github.io/js/pace.min.js" data-no-instant></script>



<script src="https://systemime.github.io/js/instantclick.min.js" data-no-instant></script>
   <script data-no-instant>
   InstantClick.on('change', function(isInitialLoad) {
     if (isInitialLoad === false) {
       if (typeof MathJax !== 'undefined') 
         MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
       if (typeof prettyPrint !== 'undefined') 
         prettyPrint();
       if (typeof _hmt !== 'undefined')  
         _hmt.push(['_trackPageview', location.pathname + location.search]);
       if (typeof ga !== 'undefined')  
           ga('send', 'pageview', location.pathname + location.search);
     }
   });
   InstantClick.init();
</script>




<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.7.1/gist-embed.min.js"></script>


<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-3925981084585036",
    enable_page_level_ads: true
  });
</script>



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/photoswipe.min.css" integrity="sha256-sCl5PUOGMLfFYctzDW3MtRib0ctyUvI9Qsmq2wXOeBY=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.1/default-skin/default-skin.min.css" integrity="sha256-BFeI1V+Vh1Rk37wswuOYn5lsTcaU96hGaI7OUVCLjPc=" crossorigin="anonymous" />



<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

<div class="pswp__bg"></div>

<div class="pswp__scroll-wrap">
    
    <div class="pswp__container">
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
      <div class="pswp__item"></div>
    </div>
    
    <div class="pswp__ui pswp__ui--hidden">
    <div class="pswp__top-bar">
      
      <div class="pswp__counter"></div>
      <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
      <button class="pswp__button pswp__button--share" title="Share"></button>
      <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
      <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
      
      
      <div class="pswp__preloader">
        <div class="pswp__preloader__icn">
          <div class="pswp__preloader__cut">
            <div class="pswp__preloader__donut"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
      <div class="pswp__share-tooltip"></div>
    </div>
    <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
    </button>
    <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
    </button>
    <div class="pswp__caption">
      <div class="pswp__caption__center"></div>
    </div>
    </div>
    </div>
</div>

</head>

  <body>
    <nav class="navbar navbar-default navbar-fixed-top navbar-custom">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="https://systemime.github.io">听风的小站</a>
    </div>
    <div class="collapse navbar-collapse" id="main-navbar">
      <ul class="nav navbar-nav navbar-right">
        
          
            <li>
		    <a title="博客" href="https://systemime.github.io/blog/">博客</a>
              
              
            </li>
          
        
          
            <li>
		    <a title="片刻" href="https://systemime.github.io/moment/">片刻</a>
              
              
            </li>
          
        
          
            <li>
		    <a title="关于" href="https://systemime.github.io/about/">关于</a>
              
              
            </li>
          
        
          
            <li>
		    <a title="留言" href="https://systemime.github.io/message/">留言</a>
              
              
            </li>
          
        

        

        
        
      </ul>
    </div>

    <div class="avatar-container">
      <div class="avatar-img-border">
        
      </div>
    </div>

  </div>
</nav>






    
  <header class="header-section ">
    <div class="intro-header no-img">
      <div class="container">
        <div class="row">
          <div class="col-lg-12 col-md-12 col-md-offset-0">
            <div class="page-heading">
              <h1>#杂技浅尝</h1>
              <hr class="small">
            </div>
          </div>
        </div>
      </div>
    </div>
  </header>

    
  <div class="container" role="main">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        
        <div class="posts-list">
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-05/%E5%B0%8F%E8%AE%B0docker%E6%96%B0linux%E5%AE%B9%E5%99%A8%E5%90%AF%E5%8A%A8%E5%90%8E%E6%97%A0ifconfig%E5%92%8Cping/">
                <h2 class="post-title">【小记】Docker新linux容器启动后无ifconfig和ping</h2>

                
              </a>

              <p class="post-meta">
                Posted on May 7, 2019
              </p>
              <div class="post-entry">
                
                  <h3 id="命令第一条">命令第一条</h3>
<pre><code>apt-get update

apt install net-tools       # ifconfig 
</code></pre><h3 id="命令第二条">命令第二条</h3>
<pre><code>apt install iputils-ping     # ping
</code></pre><h3 id="ssh">ssh</h3>
<pre><code>apt-get update
apt-get install openssh-server  # 服务
apt-get install openssh-client  # 客户

# 编辑配置文件，
vim /etc/ssh/sshd_config

# 修改内容
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      %h/.ssh/authorized_keys



ps -e | grep ssh	# 检查是否运行
service ssh (re)start	# 启动
或
/etc/init.d/ssh -start 

</code></pre><h3 id="免密">免密</h3>
<pre><code>ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

id_rsa.pub存入authorized_keys

cat id_rsa.pub &gt;&gt; authorized_keys

id_rsa.pub再发送到其他机器并写入authorized_keys

# 复制公钥方式
ssh-copy-id root@192.168.231.31
</code></pre><h3 id="换源">换源</h3>
<p>中科大的源</p>
<ul>
<li>编辑<code>/etc/apt/sources.list</code>文件</li>
<li>注释其中其他内容</li>
<li>末尾添加</li>
</ul>
<pre><code>deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
</code></pre><ul>
<li>输入&gt; apt-get update</li>
</ul>

                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/docker/">Docker</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/%E5%AE%B9%E5%99%A8/">容器</a>&nbsp;
                  
                </span>
              

            </article>
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-05/docker%E5%AE%B9%E5%99%A8%E6%8C%82%E8%BD%BD%E6%9C%AC%E5%9C%B0%E5%85%B1%E4%BA%AB%E6%96%87%E4%BB%B6%E5%A4%B9/">
                <h2 class="post-title">Docker容器挂载本地共享文件夹</h2>

                
              </a>

              <p class="post-meta">
                Posted on May 7, 2019
              </p>
              <div class="post-entry">
                
                  <h3 id="docker挂载本地目录的方法">Docker挂载本地目录的方法</h3>
<p>Docker容器启动时，我们可以使用<code>-v</code>参数来挂载主机下的一个目录
比如，我需要启动一个ubuntu的容器，并把/opt文件挂载在这个容器上做共享文件夹</p>
<pre><code># a3551444fc85是我的镜像ID
docker run -t -i -v /opt:/soft a3551444fc85 /bin/bash
</code></pre><p>这样启动后容器会自动在根目录下创建soft文件夹，同时也就要求了**/soft必须写绝对路径**</p>
<h3 id="如果主机不存在该目录则会自动生成">如果主机不存在该目录，则会自动生成</h3>
<pre><code>[root@sys ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
</code></pre><p>启动后</p>
<pre><code>[root@sys ~]# docker run -it -v /test:/soft centos /bin/bash
[root@a3551444fc85 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  soft  srv  sys  tmp  usr  var
</code></pre><p>查看宿主机，发现新增了一个/test目录</p>
<pre><code>[root@sys ~]# ls /
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  test  tmp  usr  var
</code></pre><h3 id="如果主机使用相对路径">如果主机使用相对路径</h3>
<pre><code># docker run -it -v test1:/soft centos /bin/bash
</code></pre><p>再到宿主机上查看是否新增了一个/test1目录，结果没有，是不是因为我用的是相对路径，所以生成的test1目录在当前目录下，结果发现还是没有。那容器内的/soft目录挂载到哪里去了？通过docker inspect命令，查看容器“Mounts”那一部分，我们可以得到这个问题的答案。</p>
<pre><code>&quot;Mounts&quot;:[
        {
            &quot;Name&quot;: &quot;test1&quot;,
            &quot;Source&quot;: &quot;/var/lib/docker/volumes/test1/_data&quot;,
            &quot;Destination&quot;: &quot;/soft&quot;,
            &quot;Driver&quot;: &quot;local&quot;,
            &quot;Mode&quot;: &quot;z&quot;,
            &quot;RW&quot;: true
        }
    ],
	
# 可以看出，容器内的/soft目录挂载的是宿主机上的/var/lib/docker/volumes/test1/_data目录
</code></pre><p>原来，所谓的相对路径指的是/var/lib/docker/volumes/，与宿主机的当前目录无关。</p>
<h3 id="如果只是-v指定一个目录这个又是如何对应呢">如果只是-v指定一个目录，这个又是如何对应呢？</h3>
<p>启动一个容器</p>
<pre><code>[root@localhost ~]# docker run -it -v /test2 centos /bin/bash
[root@ea24067bc902 /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  test2  tmp  usr  var
</code></pre><p>同样使用docker inspect命令查看宿主机的挂载目录</p>
<pre><code>&quot;Mounts&quot;:[
        {
            &quot;Name&quot;: &quot;96256232eb74edb139d652746f0fe426e57fbacdf73376963e3acdb411b3d73a&quot;,
            &quot;Source&quot;: &quot;/var/lib/docker/volumes/96256232eb74edb139d652746f0fe426e57fbacdf73376963e3acdb411b3d73a/_data&quot;,
            &quot;Destination&quot;: &quot;/test2&quot;,
            &quot;Driver&quot;: &quot;local&quot;,
            &quot;Mode&quot;: &quot;&quot;,
            &quot;RW&quot;: true
        }
    ],
</code></pre><p>可以看出，同3中的结果类似，只不过，它不是相对路径的目录名，而是随机生成的一个目录名。</p>
<h3 id="如果在容器内修改了目录的属主和属组那么对应的挂载点是否会修改呢">如果在容器内修改了目录的属主和属组，那么对应的挂载点是否会修改呢？</h3>
<p>首先开启一个容器，查看容器内/soft目录的属性</p>
<pre><code>[root@localhost ~]# docker run -it -v /test:/soft centos /bin/bash
[root@b5ed8216401f /]# ll -d /soft/
drwxr-xr-x 2 root root 6 Sep 24 03:48 /soft/
</code></pre><p>查看宿主机内/test目录的属性</p>
<pre><code>[root@localhost ~]# ll -d /test/
drwxr-xr-x 2 root root 6 Sep 24 11:48 /test/
</code></pre><p>在容器内新建用户，修改/soft的属主和属组</p>
<pre><code>[root@b5ed8216401f /]# useradd victor
[root@b5ed8216401f /]# chown -R victor.victor /soft/
[root@b5ed8216401f /]# ll -d /soft/
drwxr-xr-x 2 victor victor 6 Sep 24 03:48 /soft/
</code></pre><p>再来看看宿主机内/test目录的属主和属组是否会发生变化？</p>
<pre><code>[root@localhost ~]# ll -d /test/
drwxr-xr-x 2 mycat mycat 6 Sep 24 11:48 /test/
</code></pre><p>竟然变为mycat了。。。</p>
<p>原来，这个与UID有关系，UID，即“用户标识号”，是一个整数，系统内部用它来标识用户。一般情况下它与用户名是一一对应的。</p>
<p>首先查看容器内victor对应的UID是多少，</p>
<pre><code>[root@b5ed8216401f /]# cat /etc/passwd | grep victor
victor❌1000:1000::/home/victor:/bin/bash
</code></pre><p>victor的UID为1000，那么宿主机内1000对应的用户是谁呢？</p>
<pre><code>[root@localhost ~]# cat /etc/passwd |grep 1000
mycat❌1000:1000::/home/mycat:/bin/bash
</code></pre><p>可以看出，宿主机内UID 1000对应的用户是mycat。</p>
<h3 id="容器销毁了在宿主机上新建的挂载目录是否会消失">容器销毁了，在宿主机上新建的挂载目录是否会消失？</h3>
<p>在这里，主要验证两种情况：一、指定了宿主机目录，即 -v /test:/soft。二、没有指定宿主机目录，即-v /soft</p>
<p><strong>第一种情况：</strong></p>
<pre><code>[root@localhost ~]# rm-rf/test --首先删除宿主机的/test目录
[root@localhost ~]# ls /    --可以看到，宿主机上无/test目录
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@localhost ~]# docker run -it --name=centos_test -v /test:/soft centos /bin/bash  --启动容器，为了删除方便，我用--name参数指定了容器的名字
[root@82ad7f3a779a /]# exit
exit
[root@localhost ~]# docker rm centos_test   --删除容器
centos_test
[root@localhost ~]# ls /   --发现 /test目录依旧存在
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  test  tmp  usr  var
</code></pre><p>可以看出，即便容器销毁了，新建的挂载目录不会消失。进一步也可验证，如果宿主机目录的属主和属组发生了变化，容器销毁后，宿主机目录的属主和属组不会恢复到挂载之前的状态。
第二种情况，通过上面的验证知道，如果没有指定宿主机的目录，则容器会在/var/lib/docker/volumes/随机配置一个目录，那么我们看看这种情况下的容器销毁是否会导致相应目录的删除</p>
<p>首先启动容器</p>
<pre><code>[root@localhost ~]# docker run -it --name=centos_test -v /soft centos /bin/bash
[root@6b75579ec934 /]# exit
exit
</code></pre><p>通过docker inspect命令查看容器在宿主机上生成的挂载目录</p>
<pre><code>&quot;Mounts&quot;:[
        {
            &quot;Name&quot;: &quot;b53164cb1c9f1917788638692fb22ad11994cf1fbbc2461b6c390cd3e10ea301&quot;,
            &quot;Source&quot;: &quot;/var/lib/docker/volumes/b53164cb1c9f1917788638692fb22ad11994cf1fbbc2461b6c390cd3e10ea301/_data&quot;,
            &quot;Destination&quot;: &quot;/soft&quot;,
            &quot;Driver&quot;: &quot;local&quot;,
            &quot;Mode&quot;: &quot;&quot;,
            &quot;RW&quot;: true
        }
    ],
# 对应的是/var/lib/docker/volumes/b53164cb1c9f1917788638692fb22ad11994cf1fbbc2461b6c390cd3e10ea301/_data目录
</code></pre><p>销毁容器，看目录是否存在</p>
<pre><code>[root@localhost ~]# docker rm centos_test
centos_test
[root@localhost ~]# ll /var/lib/docker/volumes/b53164cb1c9f1917788638692fb22ad11994cf1fbbc2461b6c390cd3e10ea301
total 0
drwxr-xr-x 2 root root 6 Sep 24 14:25 _data
</code></pre><p>发现该目录依旧存在，即便重启了docker服务，该目录依旧存在</p>
<pre><code>[root@localhost ~]# systemctl restart docker
[root@localhost ~]# ll /var/lib/docker/volumes/b53164cb1c9f1917788638692fb22ad11994cf1fbbc2461b6c390cd3e10ea301
total 0
drwxr-xr-x 2 root root 6 Sep 24 14:25 _data
</code></pre><h3 id="挂载宿主机已存在目录后在容器内对其进行操作报permission-denied">挂载宿主机已存在目录后，在容器内对其进行操作，报“Permission denied”。</h3>
<p><strong>可通过两种方式解决：</strong></p>
<p>1 关闭selinux。</p>
<p>临时关闭：<code># setenforce 0</code></p>
<p>永久关闭：修改<code>/etc/sysconfig/selinux</code>文件，将<code>SELINUX</code>的值设置为<code>disabled</code>。</p>
<p>2 以特权方式启动容器</p>
<p>指定<code>--privileged</code>参数</p>
<p>如：<code># docker run -it --privileged=true -v /test:/soft centos /bin/bash</code></p>
<p>docker挂载本地目录实现文件共享：</p>
<p>Docker可以支持把一个宿主机上的目录挂载到镜像里。</p>
<blockquote>
<p>docker run -it -v /home/dock/Downloads:/usr/Downloads ubuntu64 /bin/bash</p>
</blockquote>
<p>通过-v参数，冒号前为宿主机目录，必须为绝对路径，冒号后为镜像内挂载的路径。
<img src="https://github.com/systemime/my_image/blob/master/docker%E5%AE%B9%E5%99%A8%E6%8C%82%E8%BD%BD%E5%85%B1%E4%BA%AB/TIM%E5%9B%BE%E7%89%8720190507200917.png?raw=true" alt="图片1"></p>
<p>现在镜像内就可以共享宿主机里的文件了。</p>
<p>默认挂载的路径权限为读写。如果指定为只读可以用：ro</p>
<pre><code>docker run -it -v /home/dock/Downloads:/usr/Downloads:ro ubuntu64 /bin/bash
</code></pre><p>docker还提供了一种高级的用法。叫数据卷。</p>
<p>数据卷：“其实就是一个正常的容器，专门用来提供数据卷供其它容器挂载的”。感觉像是由一个容器定义的一个数据挂载信息。其他的容器启动可以直接挂载数据卷容器中定义的挂载信息。</p>
<p>看示例：</p>
<pre><code>docker run -v /home/dock/Downloads:/usr/Downloads  --name dataVol ubuntu64 /bin/bash
</code></pre><p>创建一个普通的容器。用&ndash;name给他指定了一个名（不指定的话会生成一个随机的名子）。
<img src="https://github.com/systemime/my_image/blob/master/docker%E5%AE%B9%E5%99%A8%E6%8C%82%E8%BD%BD%E5%85%B1%E4%BA%AB/1445846124126096.png?raw=true" alt="图2"></p>
<p>再创建一个新的容器，来使用这个数据卷。</p>
<blockquote>
<p>docker run -it &ndash;volumes-from dataVol ubuntu64 /bin/bash</p>
</blockquote>
<p>`&ndash;volumes-from``用来指定要从哪个数据卷来挂载数据。</p>
<p><img src="https://github.com/systemime/my_image/blob/master/docker%E5%AE%B9%E5%99%A8%E6%8C%82%E8%BD%BD%E5%85%B1%E4%BA%AB/3.png?raw=true" alt="图3"></p>

                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/docker/">Docker</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/%E5%85%B1%E4%BA%AB/">共享</a>&nbsp;
                  
                </span>
              

            </article>
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-05/django%E5%85%B3%E9%97%ADdegug%E5%BD%B1%E5%93%8Dcss%E6%A0%B7%E5%BC%8F%E5%8F%97%E5%BD%B1%E5%93%8D/">
                <h2 class="post-title">Django关闭DEGUG影响css样式受影响</h2>

                
              </a>

              <p class="post-meta">
                Posted on May 5, 2019
              </p>
              <div class="post-entry">
                
                  <h2 id="1如何关闭debug">1、如何关闭DEBUG</h2>
<p>在<code>setting.py</code>中修改如下配置</p>
<pre><code>```
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

USE_TZ = False
```
</code></pre>
<h2 id="2恢复普通url链接样式">2、恢复普通url链接样式：</h2>
<ul>
<li>
<p>在<code>setting.py</code>中修改如下配置</p>
<pre><code>STATIC_URL = '/static/'
if DEBUG:
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static'),
    ]
else:
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
</code></pre><pre><code>
</code></pre></li>
<li>
<p>在<code>urls.py</code>中，加入</p>
<pre><code>from django.conf.urls import url
from django.conf import settings
from django.views.static import serve
  
...
  
# 确保设置DEBUG为False时样式显示正常
if not settings.DEBUG:
    urlpatterns += [
        url(r'static/(?P&lt;path&gt;.*)$', serve,
            {'document_root': settings.STATIC_ROOT, 'show_indexes': settings.DEBUG})
    ]
</code></pre><pre><code>   
</code></pre></li>
</ul>
<h2 id="3恢复admin界面样式">3、恢复admin界面样式</h2>
<p><strong>上一步在<code>setting.py</code>、<code>urls.py</code>里修改的内容必须有</strong></p>
<p>运行命令, 把admin相关样式移动到自定义的样式文件夹中，比如<code>static</code></p>
<pre><code>python manage.py collectstatic
</code></pre><p>基本就可以了，如果还不行，加上这个</p>
<pre><code>url(r'^static/(?P&lt;path&gt;.*)$', 'django.views.static.serve',{'document_root': settings.STATIC_ROOT }),
</code></pre>
                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/django/">Django</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/%E6%A0%B7%E5%BC%8F/">样式</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/debug/">DEBUG</a>&nbsp;
                  
                </span>
              

            </article>
          
            <article class="post-preview">
              <a href="https://systemime.github.io/blog/2019-04/linux%E4%B8%8Bwhichwhereislocatefind%E7%9A%84%E5%8C%BA%E5%88%AB/">
                <h2 class="post-title">Linux下which、whereis、locate、find的区别</h2>

                
              </a>

              <p class="post-meta">
                Posted on April 20, 2019
              </p>
              <div class="post-entry">
                
                  <h1 id="linux下-which--whereis--locate--find的区别">Linux下 which | whereis | locate | find的区别</h1>
<ul>
<li><code>which</code>      查看可执行文件的位置</li>
<li><code>whereis</code>    查看文件的位置</li>
<li><code>locate</code>     配合数据库查看文件位置</li>
<li><code>find</code>       实际搜寻硬盘查询文件名称</li>
</ul>
<h2 id="1-find">1. find</h2>
<p>find是最常用和最强大的查找命令。它能做到实时查找，精确查找，但速度慢。</p>
<p>find的使用格式如下：</p>
<blockquote>
<p>find [指定目录] [指定条件] [指定动作]</p>
</blockquote>
<ul>
<li>指定目录：是指所要搜索的目录和其子目录。如果不指定，则默认为当前目录。</li>
<li>指定条件：是指所要搜索的文件的特点。</li>
<li>指定动作：是指对搜索的结果如何处理。</li>
</ul>
<p><strong>常见选项:</strong></p>
<ul>
<li>-name  根据文件名称查找（严格区分大小写，如果文件名中间有空格，则必须把文件名用双引号引起来）</li>
<li>-iname  根据文件名查找（不区分大小写）</li>
<li>-regex &ldquo;PATTERN&rdquo; 正则表达式匹配</li>
<li>-user  根据文件属主进行查找</li>
<li>-group  根据文件属组进行查找</li>
<li>-uid  根据文件的uid查找</li>
<li>-gid   根据用户的gid查找</li>
<li>-nouser  查看所有的没有属主的文件</li>
<li>-nogroup   查看所有的没有属组的文件</li>
</ul>
<p><strong>举例</strong></p>
<ul>
<li>查看tmp目录下，文件属主为redhat的文件</li>
</ul>
<pre><code>#ls -l `find /tmp -user redhat`
</code></pre><ul>
<li>查看根目录下文件或文件名为xxx的文件或文件夹</li>
</ul>
<pre><code>#find / -name xxx
</code></pre><h2 id="2-whereis">2. whereis</h2>
<p>whereis命令只能用于搜索程序名，而且只搜索二进制文件（参数-b）、man说明文件（参数-m）和源代码文件（参数-s）。如果省略参数，则返回所有信息。</p>
<p>语法：</p>
<blockquote>
<p>whereis [-bmsu] 文件或者目录名称</p>
</blockquote>
<p>参数说明：</p>
<ul>
<li><code>-b</code> ： 只找二进制文件</li>
<li><code>-m</code>： 只找在说明文件manual路径下的文件</li>
<li><code>-s</code> ： 只找source源文件</li>
<li><code>-u</code> ： 没有说明文档的文件
例如：</li>
</ul>
<pre><code>[root@redhat ~]# whereis passwd 
passwd: /usr/bin/passwd /etc/passwd /usr/bin/X11/passwd /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1.gz /usr/share/man/man1/passwd.1ssl.gz
将和passwd文件相关的文件都查找出来 

[root@redhat ~]# whereis -b passwd 
passwd: /usr/bin/passwd /etc/passwd /usr/bin/X11/passwd 
只将二进制文件 查找出来 
</code></pre><p><strong>和find相比，whereis查找的速度非常快</strong></p>
<p>这是因为linux系统会将系统内的所有文件都记录在一个数据库文件中，当使用whereis和下面即将介绍的locate时，会从数据库中查找数据，而不是像find命令那样，通过遍历硬盘来查找，效率自然会很高。</p>
<p>但是该数据库文件并不是实时更新，默认情况下时一星期更新一次，因此，我们在用whereis和locate 查找文件时，有时会找到已经被删除的数据，或者刚刚建立文件，却无法查找到，原因就是因为数据库文件没有被更新。</p>
<h2 id="3--which">3.  which</h2>
<p>which命令是查找命令是否存在，以及命令的存放位置在哪儿。</p>
<p>语法：</p>
<blockquote>
<p>which 可执行文件名称</p>
</blockquote>
<p>例如：</p>
<pre><code>[root@sys ~]# which passwd 
/usr/bin/passwd 
</code></pre><p>which是通过 PATH 环境变量到该路径内查找可执行文件，所以基本的功能是寻找可执行文件</p>
<h2 id="4-locate">4. locate</h2>
<p><strong>locate命令不是实时查找，所以查找的结果不精确，但查找速度很快。</strong></p>
<p>因为它查找的不是目录，而是一个数据库（/var/lib /locatedb），这个数据库中含有本地所有文件信息。</p>
<p>Linux系统自动创建这个数据库，并且每天自动更新一次，所以使用locate命令查不到最 新变动过的文件。</p>
<p>为了避免这种情况，可以在使用locate之前，先使用updatedb命令，手动更新数据库。</p>
<p>格式</p>
<blockquote>
<p>locate 文件或者目录名称</p>
</blockquote>
<p>例如：</p>
<pre><code>查找所有包含passwd的文件
#locate passwd

查找所有包含passwd的文件，并且只显示前十个
#locate -n 10 passwd
</code></pre>
                
              </div>

              
                <span class="post-meta">
                  
                    #<a href="https://systemime.github.iotags/linux/">Linux</a>&nbsp;
                  
                    #<a href="https://systemime.github.iotags/%E6%9F%A5%E6%89%BE/">查找</a>&nbsp;
                  
                </span>
              

            </article>
          
        </div>
        
          <ul class="pager main-pager">
            
              <li class="previous">
                <a href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/3">&larr; Newer Posts</a>
              </li>
            
            
              <li class="next">
                <a href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/5">Older Posts &rarr;</a>
              </li>
            
          </ul>
        
      </div>
    <div align="center" class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        

<ul class="pagination">
    
    <li class="page-item">
        <a href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/" class="page-link" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
    </li>
    
    <li class="page-item">
    <a href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/3/" class="page-link" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
    </li>
    
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/">1</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/2/">2</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/3/">3</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item active"><a class="page-link" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/4/">4</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/5/">5</a></li>
    
    
    
    
    
    
        
        
    
    
    <li class="page-item disabled"><span aria-hidden="true">&nbsp;&hellip;&nbsp;</span></li>
    
    
    
    
    
    
        
        
    
    
    
    
    
    
    
        
        
    
    
    
    
    
    
    
        
        
    
    
    
    
    
    
    
        
        
    
    
    
    
    
    
    
        
        
    
    
    <li class="page-item"><a class="page-link" href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/11/">11</a></li>
    
    
    <li class="page-item">
    <a href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/5/" class="page-link" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
    </li>
    
    <li class="page-item">
        <a href="https://systemime.github.io/series/%E6%9D%82%E6%8A%80%E6%B5%85%E5%B0%9D/page/11/" class="page-link" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
    </li>
    
</ul>


        
        
        
        
        
      </div>
    </div>
  </div>

    <div class="rocket"><img src="https://systemime.github.io/img/rocket_up.png" alt="" width="100" height="100"></div>
<script>
    $(function () {
      $(window).scroll(function () {
        
        if ($(window).scrollTop() >= 1000) {
          $('.rocket').stop().fadeIn(1000);
        }else {
          $('.rocket').stop().fadeOut(1000);
        }
      })
      
      $('.rocket').click(function () {
        $('html,body').stop().animate({scrollTop:0},400);
       
      })
    })

</script>

    
    <div id="landlord">
        <div class="message" style="opacity:0"></div>
        <canvas id="live2d" width="280" height="250" class="live2d"></canvas>
        <div class="hide-button">隐藏</div>
    </div>
    
    <footer id="copyright">
  <div class="container">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
        <ul class="list-inline text-center footer-links">
          
          
        </ul>
        <p class="credits copyright text-muted">
        &copy;2017-2018
          
          &nbsp;&bull;&nbsp;
          September 20,2019
          updated
          
            &nbsp;&bull;&nbsp;
            <a href="https://systemime.github.io">Home</a>
          
        </p>

        <p class="credits theme-by text-muted">
        <a href="https://servicemesher.github.io" target="_blank">ServiceMesher</a>&nbsp;&bull;&nbsp;<a href="https://github.com/yangchuansheng/k8s-knowledge" target="_blank">Kubernetes 知识图谱</a>
        <br />
        <span id="busuanzi_container_site_pv">
            本站已被访问 <span id="busuanzi_value_site_pv"></span> 次啦
        </span>
        <span id="busuanzi_container_site_uv">
            &ensp;|&ensp;&thinsp;您是第 <span id="busuanzi_value_site_uv"></span> 位到访的小伙伴喔
        </span>
        </p>
        
        <p class="credits theme-by text-muted">
          <a href="http://gohugo.io">Hugo v0.67.0</a> powered &nbsp;&bull;&nbsp; Theme by <a href="http://deanattali.com/beautiful-jekyll/">Beautiful Jekyll</a> adapted to <a href="https://github.com/halogenica/beautifulhugo">Beautiful Hugo</a>
          
          <center><section class="credits theme-by text-muted">
    <span class="footer__copyright">
    <div>
    <span id="span_dt_dt"> </span>
    <script language="javascript">
      function show_date_time(){
        window.setTimeout("show_date_time()", 1000);
        BirthDay=new Date("7/8/2017 10:56:12");
        today=new Date();
        timeold=(today.getTime()-BirthDay.getTime());
        sectimeold=timeold/1000
        secondsold=Math.floor(sectimeold);
        msPerDay=24*60*60*1000
        e_daysold=timeold/msPerDay
        daysold=Math.floor(e_daysold);
        e_hrsold=(e_daysold-daysold)*24;
        hrsold=Math.floor(e_hrsold);
        e_minsold=(e_hrsold-hrsold)*60;
        minsold=Math.floor((e_hrsold-hrsold)*60);
        seconds=Math.floor((e_minsold-minsold)*60);
        span_dt_dt.innerHTML="本博客已经开心运行 "+daysold+" 天 "+hrsold+" 小时 "+minsold+" 分 "+seconds+" 秒";
      }
      show_date_time();
    </script>
    </div>
</script>
</section>
</center>
        </p>
      </div>
    </div>
  </div>
</footer>


<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/bootstrap.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/photoswipe-ui-default.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/photoswipe.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/auto-render.min.js"></script>
<script src="https://systemime.github.io/js/main.js"></script>
<script src="https://systemime.github.io/js/clipboard.min.js"></script>
<script src="https://systemime.github.io/js/prism.js?t=123"></script>
<script src="https://systemime.github.io/js/highlight.min.js"></script>
<script src="https://res.cloudinary.com/jimmysong/raw/upload/rootsongjc-hugo/katex.min.js"></script>
<script src="https://systemime.github.io/js/reward.js"></script>
<script src="https://systemime.github.io/js/canvas_ribbon.js"></script>
<script> renderMathInElement(document.body); </script>

<script src="https://systemime.github.io/js/baguetteBox.js"></script>
<script> baguetteBox.run('.gallery');</script>






<script async defer src="https://buttons.github.io/buttons.js"></script>


<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
<script type="text/javascript" src="https://systemime.github.io/js/quicklink.umd.js"></script>
<script>
window.addEventListener('load', () =>{
   quicklink();
});
</script>



<script type="text/javascript">
 
var a_idx = 0;
jQuery(document).ready(function($) {
    $("body").click(function(e) {
        var a = new Array("Docker", "Kubernetes", "Prometheus", "Envoy", "Istio", "Service Mesh", "Cloud Native");
        var $i = $("<span />").text(a[a_idx]);
        a_idx = (a_idx + 1) % a.length;
        var x = e.pageX,
        y = e.pageY;
        function randomColor() {
          var flakeColor = new Array("#FFDA65", "#00BFFF", "#BA55D3", "#FFA07A", "#87CEEB", "#FFB6C1");
          var snowColor = flakeColor[Math.floor(flakeColor.length * Math.random())];
          return snowColor;
        }
        $i.css({
            "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
            "top": y - 20,
            "left": x,
            "position": "absolute",
            "font-weight": "bold",
            "color": randomColor()
        });
        $("body").append($i);
        $i.animate({
            "top": y - 180,
            "opacity": 0
        },
        1500,
        function() {
            $i.remove();
        });
    });
});
</script>


<script type="text/javascript" src="https://systemime.github.io/js/lightbox.js"></script>











<script src="https://cdn.plyr.io/3.4.7/plyr.js"></script>
<script>const player = new Plyr('#player');</script>


<script async defer src="https://buttons.github.io/buttons.js"></script>


  </body>
</html>

